﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace LibSerie
{
    public abstract class SynchronizeObservableCollection<T1,T2> 
    {

        public abstract T2 Create(T1 u1);
        public abstract T1 Create(T2 u2);

        //public abstract T2 Copy(T1 u1, T2 u2);
        //public abstract T1 Copy(T2 u2, T1 u1);

        public abstract T2 Get(T1 u1);
        public abstract T1 Get(T2 u2);

        public ObservableCollection<T1> Lst1 = new ObservableCollection<T1>();
        public ObservableCollection<T2> Lst2 = new ObservableCollection<T2>();

        public SynchronizeObservableCollection(ObservableCollection<T1> lst1, ObservableCollection<T2> lst2)
        {

            Lst1 = lst1;
            Lst2 = lst2;

            Lst1.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Lst1_CollectionChanged);
            Lst2.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Lst2_CollectionChanged);

        }

        
        void Lst1_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            foreach (T1 u1 in e.NewItems)
            {
                T2 t2 = Create(u1);
                if (t2 == null) continue;
                Lst2.Add(t2);
            }

            //foreach (T1 u1 in e.OldItems)
            //{
                
            //}

        }
                

        void Lst2_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {

            

        }


    }
}
